package cn.xmkeshe.controller;

import cn.xmkeshe.back.IFleetServiceBack;
import cn.xmkeshe.model.Fleet;
import java.sql.Timestamp;
import java.util.*;

import cn.xmkeshe.utils.Log;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
public class FleetController {

  @Resource
  private IFleetServiceBack iFleetServiceBack;

//  添加车队页面
  @RequestMapping("/pages/back/fleet/addPre")
  @Log(operationName = "添加车队页面",operationType = "管理员")
  public String addPre(){
    return "/pages/back/fleet/add";
  }

  @RequestMapping("/pages/back/fleet/add")
  @ResponseBody
  @Log(operationName = "添加车队",operationType = "系统")
  public String add(Fleet fleet, HttpServletRequest request){
    String flag = "error";
    fleet.setDatetime(new Timestamp(new Date().getTime()));//订单生成日期
    if(iFleetServiceBack.add(fleet)){
      return "success";
    }
    return flag;
  }

//  修改车队信息
  @RequestMapping("/pages/back/fleet/listPre")
  @Log(operationName = "修改车队信息页面",operationType = "管理员")
  public String listPre(){
    return "/pages/back/fleet/list";
  }

  @RequestMapping("/pages/back/fleet/list")
  @ResponseBody
  @Log(operationName = "修改车队信息",operationType = "系统")
  public Map<String, Object> list(HttpServletRequest request){

    Map<String,Object> map = new HashMap<String,Object>();
    map.put("code",0);//解析接口状态，必须这样写
    map.put("msg","加载中");//解析提示文本
    map.put("data",iFleetServiceBack.findAll());//    解析数据列表
    map.put("count",100);//    解析数据长度
    System.out.println(map);
    return map;
  }

//  查询车队信息
  @RequestMapping("/pages/back/fleet/listFleet")
  @ResponseBody
  @Log(operationName = "查询车队信息",operationType = "管理员")
  public List<Fleet> findAll(){
    return iFleetServiceBack.findAll();
  }

  //  修改车队信息
  @RequestMapping("/pages/back/fleet/edit")
  @ResponseBody
  @Log(operationName = "修改车队信息",operationType = "管理员")
  public String editEdit(String introduction,String name,int fleetid){
    String flag = "error";
    if (iFleetServiceBack.editFleet(introduction,name,fleetid)){
      return "success";
    }
    return flag;
  }
}
